#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
. $basepath/../common/common.sh

app=$1;
param2=$2;
param3=$3;
logPath="";

function main(){
	ASSERT_NOT_EMPTY "$app" "请输入/usr/local/app/*gzidc*/下的应用名称";

	if [[ "erp" == "$app" ]]; then
		logPath="/usr/local/app/*gzidc.area*/ad_erp/Adempiere/jboss/server/adempiere/log/server.log";
	elif [[ "owms" == "$app" ]]; then
		area="usla"
		if [[ ! -z "$param2" ]]; then
			area=$param2;
		fi
		logPath="/usr/local/app/*${area}*/ad_owms/Adempiere/jboss/server/adempiere/log/boot.log";
	elif [[ "beetle" == "$app" ]]; then
		logPath="/usr/local/winit_tomcat/logs/catalina.out";		

	elif [[ "opc" == "$app" ]]; then

		area="gzidc.area"
		if [[ ! -z "$param2" ]]; then
			area=$param2;
		fi

		base="/usr/local/app/*${area}*/php_sellerportal/RuntimeLogs/Manage"
		year=$(ls $base|grep 2|sort -r | awk 'NR==1 {print $1}');
		month=$(ls -t $base/$year | awk 'NR==1 {print $1}')
		log=$(ls -t $base/$year/$month | awk 'NR==1 {print $1}');

		logPath=$base/$year/$month/$log;

	elif [[ "tom" == "$app" ]]; then
		subApp=$param2;

		area="gzidc.area"
		if [[ ! -z "$param3" ]]; then
			area=$param3;
		fi

		ASSERT_NOT_EMPTY "$subApp" "请输入Tom的模块名（大写），例如：UPS";
		base="/usr/local/app/*${area}*/php_tom/Logs/$subApp";
		ls $base;
		ASSERT $? "tom或sub模块的日志目录不存在"$base;
		monthYear=$(ls $base|grep 2|sort -r | awk 'NR==1 {print $1}');
		log=$(ls -t $base/$monthYear | awk 'NR==1 {print $1}');

		logPath=$base/$year/$monthYear/$log;

	else
		area="gzidc.area"
		if [[ ! -z "$param2" ]]; then
			area=$param2;
		fi

		logPath="/usr/local/app/*${area}*/tomcat_$app/logs/catalina.out"
	fi
	
	tail -300f $logPath;

	SUCESS_EXIT "查看完成"; 

}

main;